<%@ page contentType="text/html; charset=utf-8" language="java"%>
<%@ include file="/common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>管理中心 - 添加栏目</title>
	<%@ include file="/common/meta.jsp" %>
	<link href="${ctx}/css/system/general.css" rel="stylesheet" type="text/css" />
	<link href="${ctx}/css/system/main.css" rel="stylesheet" type="text/css" />
	<link href="${ctx}/css/system/category.css" rel="stylesheet" type="text/css" />	
	<script type="text/javascript" src="${ctx}/js/jquery-1.4.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/json.min.js"></script>
	<script type="text/javascript" src="${ctx}/js/swfupload/swfupload.js"></script>
	<script type="text/javascript" src="${ctx}/js/swfupload/handlers.js"></script>
	<script language="JavaScript" type="text/javascript">
	    $(document).ready(
	    function(){
	       var selectCategoryIds = document.getElementsByName("selectCategoryId");
	       if(selectCategoryIds!=null && selectCategoryIds.length>0){
	          var categoryIdParam = "";
	          for(var i=0;i<selectCategoryIds.length;i++){
	             if(i==0){
	                categoryIdParam += "?categoryId"+i+"="+selectCategoryIds[i].value;
	             }else{
	                categoryIdParam += "&categoryId"+i+"="+selectCategoryIds[i].value;
	             }
	          }
	          $.getJSON("${ctx}/member/product/find_brand_and_category_attribute"+categoryIdParam,{},function(data){
		         if(data!=null && data.length>0){
		             var brands = data[0];
		             var categoryAttributes = data[1];
		             if(brands!=null && brands.length>0){
		                $("#prdBrand").show();
		                var brandContent = "";
                        brandContent = "<select id='productBrand' name='productBrand'><option value=''>--请选择--</option>";
                        for(var i=0;i<brands.length;i++){
                           brandContent += "<option value='"+brands[i].id+"'>"+brands[i].name+"</option>"
                        }
                        brandContent += "</select>";
                        $("#product_brand").append("<div class='attr_div'><div class='attr_l_d_l' style='text-align:left;width:520px;'>"+brandContent+"</div><div style='clear:both;'></div></div>");	                     
		             }
		             if(categoryAttributes!=null && categoryAttributes.length>0){
		                for(var i=0;i<categoryAttributes.length;i++){
		                  if(categoryAttributes[i].displayType=="${CATEGORY_ATTRIBUTE_DISPLAY_TYPE_INPUTTEXT}"){
		                     $("#category_attribute").append("<div class='attr_div'><div class='attr_l_d_l'>"+categoryAttributes[i].name+"：</div><div class='attr_l_d_l' style='text-align:left;width:520px;'><input type='text' name='prd_attr_"+categoryAttributes[i].id+"'/></div><div style='clear:both;'></div></div>");
		                  }else if(categoryAttributes[i].displayType=="${CATEGORY_ATTRIBUTE_DISPLAY_TYPE_SELECT}"){
		                      var selectContent = "";
		                     if(categoryAttributes[i].candidateValues!=null && categoryAttributes[i].candidateValues.length>0){
		                        selectContent = "<select id='prd_attr_"+categoryAttributes[i].id+"' name='prd_attr_"+categoryAttributes[i].id+"'><option value=''>--请选择"+categoryAttributes[i].name+"--</option>";
		                        for(var j=0;j<categoryAttributes[i].candidateValues.length;j++){
		                           selectContent += "<option value='"+categoryAttributes[i].candidateValues[j].id+"'>"+categoryAttributes[i].candidateValues[j].value+"</option>"
		                        }
		                        selectContent += "</select>";
		                        $("#category_attribute").append("<div class='attr_div'><div class='attr_l_d_l'>"+categoryAttributes[i].name+"：</div><div class='attr_l_d_l' style='text-align:left;width:520px;'>"+selectContent+"</div><div style='clear:both;'></div></div>");
		                     }
		                  }else if(categoryAttributes[i].displayType=="${CATEGORY_ATTRIBUTE_DISPLAY_TYPE_CHECKBOX}"){
		                     var checkboxContect = "";
		                     if(categoryAttributes[i].candidateValues!=null && categoryAttributes[i].candidateValues.length>0){
		                         for(var j=0;j<categoryAttributes[i].candidateValues.length;j++){
		                             checkboxContect += "<input type='checkbox' name='prd_attr_"+categoryAttributes[i].id+"' value='"+categoryAttributes[i].candidateValues[j].id+"'/>"+categoryAttributes[i].candidateValues[j].value;
		                         }
		                         $("#category_attribute").append("<div class='attr_div'><div class='attr_l_d_l'>"+categoryAttributes[i].name+"：</div><div class='attr_l_d_l' style='text-align:left;width:520px;'>"+checkboxContect+"</div><div style='clear:both;'></div></div>");
		                     }
		                  }
		                }
		             }
		         }
		       });
	       }
	    }); 
        var swfu;
        window.onload = function () {
			swfu = new SWFUpload({
				upload_url: "${ctx}/swfupload",
				post_params: {},
	
				// File Upload Settings
				file_size_limit : "2 MB",
				file_types : "*.jpg;*.png",
				file_types_description : "JPG Images; PNG Image",
				file_upload_limit : 0,
	
				// Event Handler Settings - these functions as defined in Handlers.js
				//  The handlers are not part of SWFUpload but are part of my website and control how
				//  my website reacts to the SWFUpload events.
				swfupload_preload_handler : preLoad,
				swfupload_load_failed_handler : loadFailed,
				file_queue_error_handler : fileQueueError,
				file_dialog_complete_handler : fileDialogComplete,
				upload_progress_handler : uploadProgress,
				upload_error_handler : uploadError,
				upload_success_handler : uploadSuccess,
				upload_complete_handler : uploadComplete,
	
				// Button Settings
				button_image_url : "${ctx}/js/swfupload/SmallSpyGlassWithTransperancy_17x18.png",
				button_placeholder_id : "spanButtonPlaceholder",
				button_width: 180,
				button_height: 18,
				button_text : '<span class="button">请选择图片<span class="buttonSmall">(2 MB Max)</span></span>',
				button_text_style : '.button { font-family: Helvetica, Arial, sans-serif; font-size: 12pt; } .buttonSmall { font-size: 10pt; }',
				button_text_top_padding: 0,
				button_text_left_padding: 18,
				button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
				button_cursor: SWFUpload.CURSOR.HAND,
				
				// Flash Settings
				flash_url : "${ctx}/js/swfupload/swfupload.swf",
				flash9_url : "${ctx}/js/swfupload/swfupload_fp9.swf",
	
				custom_settings : {
					upload_target : "divFileProgressContainer",
					image_width:280,
					image_height:280,
					image_path:"${PRODUCT_IMAGE_PATH}",
					thumbnail_img_div_id:"thumbnails",
					image_file_names:"imageNames"
				},
				
				// Debug Settings
				debug: false
			});
		};
	 
	</script>
      <style>
       <!--
        body{
      	   font-size:13px;
      	}
      	.product-img-div{
      	   margin-left:5px;
      	}
       -->
      </style> 
</head>
<body>
<h1>
<span class="action-span"><a href="${ctx}/system/newscolumn/manage">产品列表</a></span>
<span class="action-span1"><a href="#">管理中心</a>  - 发布产品信息 </span>
<div style="clear:both"></div>
</h1>
<div class="main-div">
   <form action="${ctx}/member/product/reselect_category" method="post">
    <table width="100%" id="general-table">
      <tr>
        <td width="60%">您选择的类目：
        <c:forEach items="${selectCategoryList}" var="varTemp" varStatus="varStatusTemp">
        <input type="hidden" name="selectCategoryId" id="selectCategoryId${varStatusTemp.index}" value="${varTemp.id}"/>
         <c:choose>
           <c:when test="${varStatusTemp.last==true}">
        ${varTemp.name}
        <input type="hidden" name="categoryId" id="categoryId" value="${varTemp.id}"/>
           </c:when>
           <c:otherwise>
        ${varTemp.name} &gt;
           </c:otherwise>
         </c:choose>
        </c:forEach>
        <input type="submit" value=" 返回重选类目 " />(返回重选类目会造成已填写的信息丢失，请慎重操作！)
        </td>
      </tr>
    </table>
   </form>
</div>
<div class="main-div">
  <form:form modelAttribute="product" action="${ctx}/member/product" method="post" name="theForm" id="theForm" onsubmit="this.submit.disabled='true';">
  <input type="hidden" name="p_cate_id" id="p_cate_id" value=""/>
  <input type="hidden" name="is_leaf" id="is_leaf" value=""/>
  <table width="100%" id="general-table">
      <tr id="prdBrand" style="display:none;">
        <td class="label"><form:label for="name" path="name" cssErrorClass="error">产品品牌</form:label></td>
        <td>
          <div id="product_brand">
          </div>
        </td>
      </tr>
      <tr>
        <td class="label"><form:label for="name" path="name" cssErrorClass="error">产品属性</form:label></td>
        <td>
          <div id="category_attribute">
          </div>
        </td>
      </tr>
      <tr>
        <td class="label"><form:label for="name" path="name" cssErrorClass="error">产品名称</form:label></td>
        <td>
          <form:input path="name" maxlength="20" size="27" /> <font color="red">*</font> <form:errors path="name" /></td>
      </tr>
      <tr>
        <td class="label"><form:label for="code" path="code" cssErrorClass="error">产品编码</form:label></td>
        <td><form:input path="code" maxlength="20" size="27" /> <font color="red">*</font> <form:errors path="code" /></td>
      </tr>  
      <tr>
        <td class="label">商品图片</td>
        <td>
            <table>
               <tr>
                 <td width="180px">
					<div style="width: 180px; height: 18px; border: solid 1px #7FAAFF; background-color: #C5D9FF; padding: 2px;">
						<span id="spanButtonPlaceholder"></span>
						<input type="hidden" id="imageNames" name="imageNames"/>
					</div>
                 </td>
               </tr>
            </table>
			<div id="divFileProgressContainer" style="height: 35px;display:none;"></div>
			<div id="thumbnails">
			</div>		        
        </td>
      </tr>
      
      <tr>
        <td class="label">排序</td>
        <td>
          <form:input path="sortOrder" size="15" /></td>
      </tr>
      </table>
      <div class="button-div">
        <input type="submit" value=" 确定 " />
        <input type="reset" value=" 重置 " />
      </div>
  </form:form>
</div>
</body>
</html>